package com.lyf.aop.sguigu.transaction;

import com.alibaba.druid.pool.DruidDataSource;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.mysql.cj.jdbc.MysqlConnectionPoolDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.jta.JtaTransactionManager;

import javax.annotation.sql.DataSourceDefinition;
import javax.sql.DataSource;

/**
 * @AUTHOR LYF
 * @DATE 2022/5/15
 * @VERSION 1.0
 * @DESC
 */
@EnableTransactionManagement
@Configuration
public class TransactionConfig {

    @Bean
    DataSource dataSource(){
        //DataSource dataSource = new DataSource();
        // 需要直接连接？？
//          DataSource dataSource0 = new DriverManagerDataSource();
//          DataSource dataSource1 = new MysqlConnectionPoolDataSource();
//          DataSource dataSource2 = new DruidDataSource();

          ComboPooledDataSource dataSource3 = new ComboPooledDataSource();

          //config...

          return dataSource3;
    }
    @Bean
    PlatformTransactionManager platformTransactionManager(DataSource dataSource){
        return new DataSourceTransactionManager(dataSource());
    }

}
